

package com.hazelcast.jet.impl.processor;

import com.hazelcast.jet.aggregate.AggregateOperation;

import javax.annotation.Nonnull;

import static java.util.Collections.nCopies;

/**
 * Batch processor that computes the supplied aggregate operation. The
 * items may originate from one or more inbound edges. The supplied
 * aggregate operation must have as many accumulation functions as there
 * are inbound edges.
 */
public class AggregateP<A, R> extends GroupP<String, A, R, R> {

    private static final String CONSTANT_KEY = "ALL";

    public AggregateP(@Nonnull AggregateOperation<A, R> aggrOp) {
        super(nCopies(aggrOp.arity(), t -> CONSTANT_KEY), aggrOp, (k, r) -> r);
        keyToAcc.put(CONSTANT_KEY, aggrOp.createFn().get());
    }
}
